package cn.itsource.ymcc.service.impl;

import cn.itsource.ymcc.domain.CourseUserLearn;
import cn.itsource.ymcc.mapper.CourseUserLearnMapper;
import cn.itsource.ymcc.result.JsonResult;
import cn.itsource.ymcc.service.ICourseUserLearnService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zongchangjiang
 * @since 2023-03-31
 */
@Service
public class CourseUserLearnServiceImpl extends ServiceImpl<CourseUserLearnMapper, CourseUserLearn> implements ICourseUserLearnService {

    @Override
    public JsonResult findByCourseId(Long courseId,Long userId) {
        CourseUserLearn courseUserLearn = baseMapper.selectOne(new QueryWrapper<CourseUserLearn>()
                .eq("course_id", courseId)
                .eq("login_id", userId)
        );
        if(courseUserLearn == null){
            return JsonResult.error("请购买该课程");
        }
        return JsonResult.success().setData(JSON.toJSONString(courseUserLearn));
    }
}
